define([
    'zepto',
    'underscore',
    'backbone',
    "text!templates/client/aliPay.html",
    "wTools",

], function ($, _, Backbone, template) {
    return Backbone.View.extend({
        $el: $main,
        el: $main0,
        template: _.template(template),
        events: {},
        initialize: function () {
            $("#head").hide();
            $(".footer").hide();
            this.render();
            
            this.pay();
        },
        onBridgeReady: function () {
            try {
                AlipayJSBridge.call('tradePay',{
                    tradeNO:'2017061321001004370241150097'
                },
                function(result) {
                    alert(JSON.stringify(result));
                });
            }
            catch (e) {
                alert("errorMsg:" + e.message + ",desc:" + e.description);
            }
        },
        pay: function () {
            try {
                if (typeof AlipayJSBridge == "undefined") {
                    if (document.addEventListener) {
                        document.addEventListener('AlipayJSBridge', this.onBridgeReady(), false);
                    } else if (document.attachEvent) {
                        document.attachEvent('AlipayJSBridge', this.onBridgeReady());
                        document.attachEvent('onAlipayJSBridge', this.onBridgeReady());
                    }
                } else {
                    this.onBridgeReady();
                }
            }
            catch (e) {
                alert("errorMsg:" + e.message + ",desc:" + e.description);
            }
        },
        back: function () {
            history.back();
        },
        render: function (data) {
            var html = this.template(data);
            this.$el.html(html);
        },
        destroy: function () {
            this.undelegateEvents();
            this.$el.html("");
            delete this;
        }
    });
});